import time
from yunma import YdmVerify as ym
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()

driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", { "source": """Object.defineProperty(navigator, 'webdriver', { get: () => undefined})"""})
driver.maximize_window()  # 窗口最大化

url = "https://console.ishumei.com/new/"

driver.get(url)

time.sleep(2)
# 获取账号输入框
account = driver.find_element_by_id("Email")
account.send_keys("asdfasdfasdf")

# 获取密码输入框
pwd = driver.find_element_by_id("pwd")
pwd.send_keys("114324324")


# 创建操作链
chains = ActionChains(driver)

# 获取滑块节点
slide_btn = driver.find_element_by_class_name("shumei_captcha_slide_btn")
chains.move_to_element(slide_btn).perform()  # 在鼠标悬停在滑块上面

time.sleep(2)
# 获取图片节点
img_bg = driver.find_element_by_class_name("shumei_captcha_loaded_img_bg")
img_bg.screenshot("bg.png")  # 截图


# 通过云码平台来识别滑块之间的距离

y = ym()
with open("bg.png", "rb") as fp:
    content = fp.read()

distance = y.sin_slide_verify(content)

print(distance)
# exit()
distance1 = int(distance)-40

# 移动滑块
chains2 = ActionChains(driver)
chains2.click_and_hold(slide_btn)\
    .move_by_offset(10, 0)\
    .pause(1)\
    .move_by_offset(distance1, 0)\
    .pause(1)\
    .move_by_offset(30, 0)\
    .release()\
    .perform()\













